package com.threeti.mecool.core.domain.model.worker;

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.threeti.mecool.core.domain.model.plan.pojo.TaskAction;

public class ActionWorkerFactory {
	private static final Map<TaskAction, Class<? extends ActionWorker>> actionMap = new HashMap<TaskAction, Class<? extends ActionWorker>>();
	private Logger logger = LoggerFactory.getLogger(ActionWorkerFactory.class);
	static {
		actionMap.put(TaskAction.TAKE_PHOTO, TakePhotoActionWorker.class);
		actionMap.put(TaskAction.INPUT_TEXT, InputTextActionWorker.class);
		actionMap.put(TaskAction.INPUT_NUMBER, InputNumberActionWorker.class);
		actionMap.put(TaskAction.SELECT_SINGLE, SelectSingleActionWorker.class);
		actionMap.put(TaskAction.SELECT_MULTIPLE, SelectMultipleActionWorker.class);
	}
	
	public ActionWorker newActionWorker(TaskAction action) {
		Class<? extends ActionWorker> clazz = actionMap.get(action);
		if (clazz == null) {
			clazz = ActionWorker.class;
		}
		try {
			return clazz.newInstance();
		} catch (Exception e) {
			logger.error("Create task action worker", e);
			throw new RuntimeException(e);
		}
	}
}
